package com.zretc.controller;

import com.google.gson.Gson;
import com.zretc.entity.Address;
import com.zretc.entity.House;
import com.zretc.service.AddressService;
import com.zretc.service.HouseService;
import com.zretc.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: bLUeSuMMerDreamer
 * @createTime: 2020-07-25 01:18
 */
@Controller
@RequestMapping("/house")
public class HouseController {
    private static final Logger logger = LoggerFactory.getLogger(HouseController.class);
    @Autowired
    private HouseService houseService;
    @Autowired
    private AddressService addressService;

    @RequestMapping("/addHouse")
    @ResponseBody
    public void addHouse(String adCode, String cityCode, Double lng, Double lat, String name) {
        String AddressId = Util.getUUID();
        Address address = new Address(AddressId, name, lng, lat, null, null, name, adCode, cityCode);
        //addressService.addAddress(address);
        House house = new House(Util.getUUID(), name + " 仓库", null, address, 100000.0, null);
        houseService.addHouse(house);

    }

    @RequestMapping("/getHouseByCityCode")
    @ResponseBody
    public List<House> getHouseByCityCode(String receiveCityCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("cityCode", receiveCityCode);
        return houseService.getHousesByParams(params);

    }


    @RequestMapping("/getHouseByLevel")
    @ResponseBody
    public List<House> getHouseByCityCode(Integer level) {
        Map<String, Object> params = new HashMap<>();
        params.put("level", level);
        return houseService.getHousesByParams(params);
    }


}
